using System;
using System.ComponentModel;
using System.Transactions;

using SIS.ENT;
using SIS.DAL;


namespace SIS.BLL
{

    /// <summary>
    /// The StandardLevelTableManager class is responsible for managing BO.StandardLevelTable objects in the system.
    /// </summary>
    [DataObjectAttribute()]
    public class StandardLevelTableManager
    {

        #region "Public Methods"

        /// <summary>
        /// Gets a list with all StandardLevelTable objects in the database.
        /// </summary>
        /// <returns>A list with all StandardLevelTable from the database when the database contains any, or null otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public static StandardLevelTableList GetList(int SchoolKey, int SchoolMajorKey)
        {
            return StandardLevelTableDB.GetList(SchoolKey, SchoolMajorKey);
        }

        /// <summary>
        /// Gets a single StandardLevelTable from the database without its data.
        /// </summary>
        /// <param name="standardLevelKey">The StandardLevelKey of the StandardLevelTable in the database.</param>
        /// <returns>A StandardLevelTable object when the StandardLevelKey exists in the database, or <see langword="null"/> otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static StandardLevelTable GetItem(int standardLevelKey)
        {
            return GetItem(standardLevelKey, false);
        }

        /// <summary>
        /// Gets a single StandardLevelTable from the database.
        /// </summary>
        /// <param name="standardLevelKey">The StandardLevelKey of the StandardLevelTable in the database.</param>
        /// <param name="getStandardLevelTableRecords">Determines whether to load all associated StandardLevelTable records as well.</param>
        /// <returns>
        /// A StandardLevelTable object when the StandardLevelKey exists in the database, or <see langword="null"/> otherwise.
        /// </returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static StandardLevelTable GetItem(int standardLevelKey, bool getStandardLevelTableRecords)
        {
            StandardLevelTable myStandardLevelTable = StandardLevelTableDB.GetItem(standardLevelKey);
            //if (myStandardLevelTable != null && getStandardLevelTableRecords)
            //{
            //    myStandardLevelTable.courseDetailTables = CourseDetailTableDB.GetListByStandardLevelKey(standardLevelKey);
            //}
            //if (myStandardLevelTable != null && getStandardLevelTableRecords)
            //{
            //    myStandardLevelTable.educationPeriodStandardCourseTables = EducationPeriodStandardCourseTableDB.GetListByStandardLevelKey(standardLevelKey);
            //}
            return myStandardLevelTable;
        }

        /// <summary>
        /// Saves a StandardLevelTable in the database.
        /// </summary>
        /// <param name="myStandardLevelTable">The StandardLevelTable instance to save.</param>
        /// <returns>The new StandardLevelKey if the StandardLevelTable is new in the database or the existing StandardLevelKey when an item was updated.</returns>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
        public static int Save(StandardLevelTable myStandardLevelTable)
        {
            using (TransactionScope myTransactionScope = new TransactionScope())
            {
                int standardLevelTableStandardLevelKey = StandardLevelTableDB.Save(myStandardLevelTable);

                //foreach (CourseDetailTable myCourseDetailTable in myStandardLevelTable.courseDetailTables){
                //myCourseDetailTable.StandardLevelKey = standardLevelTableStandardLevelKey;
                //CourseDetailTableDB.Save(myCourseDetailTable);
                //}
                //foreach (EducationPeriodStandardCourseTable myEducationPeriodStandardCourseTable in myStandardLevelTable.educationPeriodStandardCourseTables){
                //myEducationPeriodStandardCourseTable.StandardLevelKey = standardLevelTableStandardLevelKey;
                //EducationPeriodStandardCourseTableDB.Save(myEducationPeriodStandardCourseTable);
                //}

                //  Assign the StandardLevelTable its new (or existing StandardLevelKey).
                myStandardLevelTable.StandardLevelKey = standardLevelTableStandardLevelKey;

                myTransactionScope.Complete();

                return standardLevelTableStandardLevelKey;
            }
        }

        /// <summary>
        /// Deletes a StandardLevelTable from the database.
        /// </summary>
        /// <param name="myStandardLevelTable">The StandardLevelTable instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public static bool Delete(StandardLevelTable myStandardLevelTable)
        {
            return StandardLevelTableDB.Delete(myStandardLevelTable.StandardLevelKey);
        }

        /// <summary>
        /// Custom Function
        /// Deletes a StandardLevelTable from the database.
        /// </summary>
        /// <param name="StandardLevelKey">The StandardLevelTable instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        public static bool Delete(int StandardLevelKey)
        {
            return StandardLevelTableDB.Delete(StandardLevelKey);
        }

        #endregion

    }

}
